From 36e2959af7af9cb8a8c5a9f4fd53e4ce808c07f3 Mon Sep 17 00:00:00 2001 From: robertl Date: Mon, 24 Jan 2005 00:13:46 +0000 Subject: [PATCH] Add explicit whitelist for Garmin waypoint names. Part 1 of 2. --- defs.h | 1 + garmin.c | 3 +++ mkshort.c | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/defs.h b/defs.h index 167d39d4e..7d8e89afc 100644 --- a/defs.h +++ b/defs.h @@ -306,6 +306,7 @@ void *MKSHORT_NEW_HANDLE(DEBUG_PARAMS); void mkshort_del_handle(void *h); void setshort_length(void *, int n); void setshort_badchars(void *, const char *); +void setshort_goodchars(void *, const char *); void setshort_mustupper(void *, int n); void setshort_mustuniq(void *, int n); void setshort_whitespace_ok(void *, int n); diff --git a/garmin.c b/garmin.c index dfaf25572..22c22df2d 100644 --- a/garmin.c +++ b/garmin.c @@ -138,6 +138,8 @@ rw_init(const char *fname) if (snwhiteopt) setshort_whitespace_ok(mkshort_handle, atoi(snwhiteopt)); + /* Technically, even this is a little loose as spaces arent allowed */ + setshort_goodchars(mkshort_handle, "ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789"); setshort_mustupper(mkshort_handle, 1); } @@ -438,6 +440,7 @@ waypoint_write(void) * but rather a garmin "fixed length" buffer that's padded * to the end with spaces. So this is NOT (strlen+1). */ +fprintf(stderr, "%s\n", ident); memcpy(way[i]->ident, ident, strlen(ident)); if (global_opts.synthesize_shortnames) { xfree(ident); diff --git a/mkshort.c b/mkshort.c index 3a9c787fa..b4b16212b 100644 --- a/mkshort.c +++ b/mkshort.c @@ -43,6 +43,7 @@ typedef struct { int whitespaceok; unsigned int target_len; char *badchars; + char *goodchars; int must_uniq; queue namelist[PRIME]; int depth[PRIME]; @@ -236,6 +237,13 @@ setshort_badchars(void *h, const char *s) hdl->badchars = xstrdup(s); } } +void +setshort_goodchars(void *h, const char *s) +{ + mkshort_handle *hdl = h; + + hdl->goodchars = xstrdup(s); +} void setshort_mustupper(void *h, int i) @@ -334,6 +342,8 @@ mkshort(void *h, const char *istring) for (i=0;ibadchars, tstring[i]) || !isascii(tstring[i])) continue; + if (hdl->goodchars && (!strchr(hdl->goodchars, tstring[i]))) + continue; *cp++ = tstring[i]; } *cp = 0; -- 2.30.2